#include "widget.h"
#include "ui_widget.h"
#include<QDebug>

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);

}

Widget::~Widget()
{
    delete ui;
}


void Widget::on_pushButton_clicked()
{
    //先获取两个输入框的时间
    QDateTime timeOld = ui->dateTimeEdit->dateTime();
    QDateTime timeNew = ui->dateTimeEdit_2->dateTime();
    qDebug()<<timeOld<<timeNew;

    //计算日期的差值
    int days = timeOld.daysTo(timeNew);//天数的差别
    int seconds = timeOld.secsTo(timeNew);//秒数的差别

    //要把秒数换算成小时
    int hous = (seconds/3600)%24;
    int day = (seconds/3600)/24;

    //把计算结果放到label中
    ui->label->setText(QString("爱你已经持续了 ") +
                       QString::number(days) +
                       QString("天零")+QString::number(hous) +
                       QString("小时"));
}
